<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>cksum</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_001_014_073">&nbsp;</a>NAME</h4><blockquote>
cksum - write file checksums and sizes
</blockquote><h4><a name = "tag_001_014_074">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

cksum <b>[</b><i>file</i> ...<b>]</b>
</code>
</pre>
</blockquote><h4><a name = "tag_001_014_075">&nbsp;</a>DESCRIPTION</h4><blockquote>
The
<i>cksum</i>
utility calculates and
writes to standard output a
cyclic redundancy check (CRC) for each input file,
and also writes to standard output the number of
octets in each file.
The CRC used is based on the polynomial used for CRC error
checking in the referenced Ethernet standard.
<p>
The encoding for the CRC checksum is defined by the generating polynomial:
<p>
<dl compact><dt> <dd>
<i>G</i>(<i>x</i>) =
<i>x</i><sup><small>32</small></sup> +
<i>x</i><sup><small>26</small></sup> +
<i>x</i><sup><small>23</small></sup> +
<i>x</i><sup><small>22</small></sup> +
<i>x</i><sup><small>16</small></sup> +
<i>x</i><sup><small>12</small></sup> +
<i>x</i><sup><small>11</small></sup> +
<i>x</i><sup><small>10</small></sup> +
<i>x</i><sup><small>8</small></sup> +
<i>x</i><sup><small>7</small></sup> +
<i>x</i><sup><small>5</small></sup> +
<i>x</i><sup><small>4</small></sup> +
<i>x</i><sup><small>2</small></sup> +
<i>x</i> +
1
</dl>
</p>
<p>
Mathematically, the CRC value corresponding to a given file is defined
by the following procedure:
<ol>
<p>
<li>
The
<i>n</i>
bits to be evaluated are considered to be the coefficients
of a mod 2 polynomial
<i>M ( x</i>
of degree
<i>n</i>-1.
These
<i>n</i>
bits are the bits from the file,
with the most significant bit being the most significant bit
of the first octet of the file and the
last bit being the least significant bit of the last octet,
padded with zero bits
(if necessary) to achieve an integral number of octets,
followed by one or more octets representing the length of the
file as a binary value, least significant octet first.
The smallest number of octets capable of representing
this integer is used.
<p>
<li>
<i>M ( x</i>
is multiplied by
<i>x</i><sup><small>32</small></sup>
(that is, shifted left 32 bits) and
divided by
<i>G ( x</i>
using mod 2 division, producing a remainder
<i>R ( x</i>
of degree &lt;= 31.
<p>
<li>
The coefficients of
<i>R ( x</i>
are considered to be a 32-bit sequence.
<p>
<li>
The bit sequence is complemented and the result is the CRC.
<p>
</ol>
</blockquote><h4><a name = "tag_001_014_076">&nbsp;</a>OPTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_077">&nbsp;</a>OPERANDS</h4><blockquote>
The following operand is supported:
<dl compact>

<dt><i>file</i><dd>A pathname of a file to be checked.
If no
<i>file</i>
operands are specified,
the standard input is used.

</dl>
</blockquote><h4><a name = "tag_001_014_078">&nbsp;</a>STDIN</h4><blockquote>
The standard input is used only if no
<i>file</i>
operands are specified.
See the INPUT FILES section.
</blockquote><h4><a name = "tag_001_014_079">&nbsp;</a>INPUT FILES</h4><blockquote>
The input files can be any file type.
</blockquote><h4><a name = "tag_001_014_080">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>
The following environment variables affect the execution of
<i>cksum</i>:
<dl compact>

<dt><i>LANG</i><dd>Provide a default value for the internationalisation variables
that are unset or null.
If
<i>LANG</i>
is unset or null, the corresponding value from the
implementation-dependent default locale will be used.
If any of the internationalisation variables contains an invalid setting, the
utility will behave as if none of the variables had been defined.


<dt><i>LC_ALL</i><dd>
If set to a non-empty string value,
override the values of all the other internationalisation variables.


<dt><i>LC_CTYPE</i><dd>
Determine the
locale for the interpretation of sequences of bytes of text data as
characters (for example, single- as opposed to multi-byte characters
in arguments).

<dt><i>LC_MESSAGES</i><dd>
Determine the locale that should be used to affect
the format and contents of diagnostic
messages written to standard error.

<dt><i>NLSPATH</i><dd>
Determine the location of message catalogues
for the processing of
<i>LC_MESSAGES .
</i>
</dl>
</blockquote><h4><a name = "tag_001_014_081">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_082">&nbsp;</a>STDOUT</h4><blockquote>
For each file processed successfully, the
<i>cksum</i>
utility will write in the following format:
<p><code>
<tt>"%u %d %s\n"</tt>, &lt;<i>checksum</i>&gt;,
&lt;<i># of octets</i>&gt;,
&lt;<i>pathname</i>&gt;
</code>
<p>
If no
<i>file</i>
operand was specified, the pathname and its leading space will be omitted.
</blockquote><h4><a name = "tag_001_014_083">&nbsp;</a>STDERR</h4><blockquote>
Used only for diagnostic messages.
</blockquote><h4><a name = "tag_001_014_084">&nbsp;</a>OUTPUT FILES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_085">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_086">&nbsp;</a>EXIT STATUS</h4><blockquote>
The following exit values are returned:
<dl compact>

<dt>0<dd>All files were processed successfully.

<dt>&gt;0<dd>An error occurred.

</dl>
</blockquote><h4><a name = "tag_001_014_087">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>
Default.
</blockquote><h4><a name = "tag_001_014_088">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
The
<i>cksum</i>
utility is typically used to
quickly compare a suspect file against a
trusted version of the same, such as to
ensure that files transmitted over noisy media arrive intact.
However, this comparison
cannot be considered cryptographically secure.
The chances of a damaged file producing the same CRC
as the original are small; deliberate
deception is difficult, but probably not impossible.
<p>
Although input files to
<i>cksum</i>
can be any type, the results need not be
what would be expected on character special device files or on file
types not described by the <b>XSH</b> specification.
Since this specification does not specify the block size used when doing input,
checksums of character special files need not process all of the data in
those files.
<p>
The algorithm is expressed in terms of a bitstream divided into octets.
If a file is transmitted between two systems and undergoes
any data transformation (such as moving 8-bit characters into 9-bit
bytes or changing &quot;Little Endian&quot; byte ordering to &quot;Big Endian&quot;),
identical CRC values cannot be expected.
Implementations performing such transformations may extend
<i>cksum</i>
to handle such situations.
</blockquote><h4><a name = "tag_001_014_089">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_090">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_001_014_091">&nbsp;</a>SEE ALSO</h4><blockquote>
None.
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>
